<?php

namespace app\util;

use Overtrue\EasySms\EasySms;

class Sms
{

    public function sendSms($phone,$code)
    {
        $config = [
            // HTTP 请求的超时时间（秒）
            'timeout' => 5.0,

            // 默认发送配置
            'default' => [
                // 网关调用策略，默认：顺序调用
                'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,

                // 默认可用的发送网关
                'gateways' => [
                    'yunpian', 'aliyun',
                ],
            ],
            // 可用的网关配置
            'gateways' => [
                'errorlog' => [
                    'file' => '/tmp/easy-sms.log',
                ],
                'yunpian' => [
                    'api_key' => '824f0ff2f71cab52936axxxxxxxxxx',
                ],
                'aliyun' => [
                    'access_key_id' => config('app.sms.AccessKey'),
                    'access_key_secret' => config('app.sms.ACCESS_KEY_SECRET'),
                    'sign_name' => config('app.sms.PHONE_SIGN_NAME'),
                ],
                //...
            ],
        ];

        $easySms = new EasySms($config);
        $templete='SMS_190920075'; //身份验证码
        $easySms->send($phone, [
            'content'  => '您的验证码为:'.$code,
            'template' => $templete,
            'data' => [
                'code' => $code
            ],
        ]);
    }
}
